package com.dream.sys.service.impl;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.dream.commons.result.PageInfo;
import com.dream.commons.utils.StringUtils;
import com.dream.sys.mapper.SysLogMapper;
import com.dream.sys.model.SysLog;
import com.dream.sys.model.DTO.SysLogReqDto;
import com.dream.sys.scan.MyException;
import com.dream.sys.service.SysLogService;

/**
 * SysLog 表数据服务层接口实现类
 */
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {
	@Autowired
	private SysLogMapper sysLogMapper;

	@Override
	public PageInfo<SysLog> selectDataGrid(SysLogReqDto sysLogReqdto) {
		Page<SysLog> page = new Page<SysLog>();
		page.setCurrent(sysLogReqdto.getPage());
		page.setSize(sysLogReqdto.getLimit());
		String loginName = sysLogReqdto.getLoginName();
		EntityWrapper<SysLog> ew = new EntityWrapper<SysLog>();
		if (StringUtils.isNotBlank(loginName)) {
			ew.like("login_name", loginName);
		}
		ew.orderBy("create_time", false);
		Page<SysLog> pageInfo = this.selectPage(page, ew);
		PageInfo<SysLog> into = new PageInfo<SysLog>(pageInfo.getTotal(), pageInfo.getRecords());
		return into;
	}

	@Override
	public int deleteLogs(String[] ids) {
		List<String> idsList = Arrays.asList(ids);
		int s = sysLogMapper.deleteBatchIds(idsList);
		if (s <= 0) {
			String msg ="操作失败";
			throw new MyException(msg);
		}
		return s;
	}

}